package sudoku

import swing._

object Main extends SimpleSwingApplication {
	var board = new Board()
	
	def top = new MainFrame {
		title = "SUDOKU!"
		  
		
		contents = new GridPanel(9, 9) {
			contents ++= 0 to 80 map (a => new Button() {  
			    name = a.toString
				action = Action("") {
					if (this.text.equals(""))
					{
						this.text = "1"
						var n = this.name.toInt

						if (n < 9)  
							board.data(0)(n) = 1
							
						if (n < 18)  
							board.data(1)(n-9) = 1	
							
						if (n < 27)  
							board.data(2)(n-18) = 1		
					}
					else if (this.text.equals("9"))
					{
						this.text = ""
						board.data(0)(0) = 0
					}
					else
					{
						var n = this.text.toInt
						n = n + 1
						this.text = n.toString
						board.data(0)(0) = n
					}
				}
			})
		}
	}
}